import {Component, ComponentFactoryResolver, ComponentRef, OnInit, ViewChild, ViewContainerRef} from '@angular/core';
import {NzGridModule} from 'ng-zorro-antd/grid';
import {NzListModule} from 'ng-zorro-antd/list';
import {CamundaService} from '../../services/camunda.service';
import { FormsModule } from '@angular/forms';
import { NzButtonModule } from 'ng-zorro-antd/button';
import { NzIconModule } from 'ng-zorro-antd/icon';
import { NzInputModule } from 'ng-zorro-antd/input';
import { NzDividerModule } from 'ng-zorro-antd/divider';
import { NzTableModule } from 'ng-zorro-antd/table';
import { NzCardModule } from 'ng-zorro-antd/card';
import {NzTabComponent} from 'ng-zorro-antd/tabs';
import {AskForLevelPersonnelMattersComponent} from '../ask_for_level/ask-for-level-personnel-matters/ask-for-level-personnel-matters.component';
import {RouterOutlet} from '@angular/router';
import {CamundaFormConfig} from '../../services/formconfig.service';

@Component({
  selector: 'app-task-list',
  standalone: true,
  imports: [AskForLevelPersonnelMattersComponent, NzCardModule, NzGridModule, NzTableModule, NzDividerModule, NzListModule, FormsModule, NzButtonModule, NzInputModule, NzIconModule, NzTabComponent, RouterOutlet],
  templateUrl: './task-list.component.html',
  styleUrl: './task-list.component.css'
})
export class TaskListComponent implements OnInit{

  constructor(private camundaService: CamundaService) {}

  /**
   * 定义子组件
   * */
  @ViewChild('container', { read: ViewContainerRef })
  container!: ViewContainerRef;

  //任务列表
  task_list:Array<any> = []

  ngOnInit(): void {
    //todo 这里理论上，是当前登录用户，这里先固定 admin
    this.camundaService.task_list("admin").subscribe(result => {
      this.task_list = result
      console.log( this.task_list )
    })

  }

  /**
   * 用来切换选择流程
   * */
  showInstance(taskId:String, formKey: String){
    this.container.clear();
    // @ts-ignore
    const componentRef = this.container.createComponent(CamundaFormConfig[formKey]);
    // @ts-ignore
    componentRef.instance.taskId = taskId
  }
}
